# 获取 CPU 核心数
if(NOT NPROC)
    set(NPROC 8)
    if(CMAKE_HOST_UNIX AND NOT WIN32)
        execute_process(
            COMMAND nproc
            OUTPUT_VARIABLE NPROC
            OUTPUT_STRIP_TRAILING_WHITESPACE
        )
    endif()
endif()
# ✅ 1 定义选项
option(BUILD_SHARED_LIBS "是否构建动态库" OFF)
option(BUILD_STATIC_LIBS "是否构建静态库" ON)
option(WITH_TEST "是否构建测试" OFF)
option(CMAKE_POSITION_INDEPENDENT_CODE "编译器会自动添加 -fPIC" ON)
# CMakeLists.txt

# 设置默认构建类型（可选）
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release CACHE STRING "设置构建类型" FORCE)
endif()

# 判断构建类型并执行不同逻辑
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    message(STATUS "🔧 构建类型: Debug")
    add_compile_definitions(DEBUG_MODE)
    add_compile_options(-O0 -g -fno-omit-frame-pointer)

elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
    message(STATUS "🚀 构建类型: Release")
    add_compile_definitions(NDEBUG)
    add_compile_options(-O3)

elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
    message(STATUS "📦 构建类型: RelWithDebInfo")
    add_compile_definitions(NDEBUG)
    add_compile_options(-O2 -g)

elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
    message(STATUS "✂️  构建类型: MinSizeRel")
    add_compile_definitions(NDEBUG)
    add_compile_options(-Os)

else()
    message(FATAL_ERROR "⚠️ 未知的构建类型: ${CMAKE_BUILD_TYPE}")
endif()

# 1 定义 ZLIB 构建 选项
option(WITH_ZLIB "是否构建 ZLIB" OFF)
set(ZLIB_TAG "v1.3.1" CACHE STRING "ZLIB 版本")
set(ZLIB_REPO "https://gitcode.com/sound/zlib.git " CACHE STRING "克隆 ZLIB 仓库")


# 2 定义 OpenSSL 构建 选项
option(WITH_OPENSSL "是否构建 OpenSSL" OFF)
set(OPENSSL_REPO "https://gitcode.com/sound/openssl.git" CACHE STRING "OpenSSL 仓库地址")
set(OPENSSL_TAG "openssl-3.0.15" CACHE STRING "OpenSSL 仓库标签")

# 2 定义 x265 构建 选项
option(WITH_X265 "是否构建 x265" OFF)
set(X265_REPO "https://gitcode.com/sound/x265.git" CACHE STRING "x265 仓库地址")
set(X265_TAG "master" CACHE STRING "x265 版本")

# 3 定义 x264 构建 选项
option(WITH_X264 "是否构建 x264" OFF)
set(X264_REPO "https://gitcode.com/sound/x264.git" CACHE STRING "x264 仓库地址")
set(X264_TAG "master" CACHE STRING "x264 版本")

# 4 mp3lame
option(WITH_MP3LAME "是否构建 mp3lame" OFF)
set(MP3LAME_REPO "https://gitcode.com/sound/lame.git" CACHE STRING "mp3lame 仓库地址")
set(MP3LAME_TAG "main" CACHE STRING "mp3lame 版本")

# 5 fdk-aac
option(WITH_FDK_AAC "是否构建 fdk-aac" OFF)
set(FDK_AAC_REPO "https://gitcode.com/sound/fdk-aac.git" CACHE STRING "fdk-aac 仓库地址")
set(FDK_AAC_TAG "v2.0.3" CACHE STRING "fdk-aac 版本")

# 6 speex
option(WITH_SPEEX "是否构建 speex" OFF)
set(SPEEX_REPO "https://gitcode.com/sound/speex.git" CACHE STRING "speex 仓库地址")
set(SPEEX_TAG "Speex-1.2.1" CACHE STRING "speex 版本")

# 7 定义 构建 ffmpeg
option(WITH_FFMPEG "是否构建 ffmpeg" OFF)
set(FFMPEG_REPO "https://gitcode.com/sound/ffmpeg.git" CACHE STRING "ffmpeg 仓库地址")
set(FFMPEG_TAG "n8.0" CACHE STRING "ffmpeg 版本")
set(MY_STRING "Hello, world! Welcome to world.")
string(REPLACE "/" "-" BUILD_FFMPEG_TARGET ${FFMPEG_TAG})
set(BUILD_FFMPEG_TARGET "ffmpeg-${BUILD_FFMPEG_TARGET}")


# 8 定义 opencv 构建 选项
option(WITH_OPENCV "是否构建 opencv" OFF)
set(OPENCV_REPO "https://gitcode.com/sound/opencv.git" CACHE STRING "opencv 仓库地址")
set(OPENCV_TAG "4.12.0" CACHE STRING "opencv 版本")

# 8 定义 ssh 构建 选项
option(WITH_SSH "是否构建 ssh" OFF)
set(SSH_REPO "https://gitcode.com/sound/libssh.git" CACHE STRING "ssh 仓库地址")
set(SSH_TAG "master" CACHE STRING "ssh 版本")

# 9 定义 ssh2 构建 选项
option(WITH_SSH2 "是否构建 ssh2" OFF)
set(SSH2_REPO "https://gitcode.com/sound/libssh2.git" CACHE STRING "ssh2 仓库地址")
set(SSH2_TAG "master" CACHE STRING "ssh2 版本")

# 10 定义 fuse3 构建 选项
option(WITH_FUSE3 "是否构建 fuse3" OFF)
set(FUSE3_REPO "https://gitcode.com/sound/libfuse.git" CACHE STRING "fuse3 仓库地址")
set(FUSE3_TAG "fuse-3.17.4" CACHE STRING "fuse3 版本")

# 11 定义 ncurses 构建 选项
option(WITH_NCURSES "是否构建 ncurses" OFF)
set(NCURSES_TAG "bookworm" CACHE STRING "ncurses 版本")
set(NCURSES_REPO "https://gitee.com/make_sound/ncurses.git" CACHE STRING "ncurses 仓库地址")

# 12 定义 boost
set(BOOST_TAG "boost_1_77_0" CACHE STRING "boost 版本")
set(BOOST_REPO "https://gitcode.com/sound/mysql-boost.git" CACHE STRING "boost 仓库地址")

# 13 定义 mysql client 构建 选项
option(WITH_MYSQL_CLIENT "是否构建 mysql client" OFF)
set(MYSQL_CLIENT_TAG "mysql-8.0.43" CACHE STRING "mysql client 版本")
set(MYSQL_CLIENT_REPO "https://gitcode.com/sound/mysql-server.git" CACHE STRING "mysql client 仓库地址")

# 14 定义 mysql-cppconn 构建 选项
option(WITH_MYSQL_CPPCONN "是否构建 mysql cppconn" OFF)
set(MYSQL_CPPCONN_TAG "8.0.33" CACHE STRING "mysql cppconn 版本")
set(MYSQL_CPPCONN_REPO "https://gitcode.com/sound/mysql-connector-cpp.git" CACHE STRING "mysql cppconn 仓库地址")

# 15 定义 nlohmann_json 构建 选项
option(WITH_NLOHMANN_JSON "是否构建 nlohmann_json" OFF)
set(NLOHMANN_JSON_TAG "develop" CACHE STRING "nlohmann_json 版本")
set(NLOHMANN_JSON_REPO "https://gitcode.com/sound/nlohmann-json.git" CACHE STRING "nlohmann_json 仓库地址")

# 16 定义 mbedtls 构建 选项
option(WITH_MBEDTLS "是否构建 mbedtls" OFF)
set(MBEDTLS_TAG "development" CACHE STRING "mbedtls 版本")
set(MBEDTLS_REPO "https://gitcode.com/sound/mbedtls.git" CACHE STRING "mbedtls 仓库地址")

# 17 定义 libpsl 构建 选项
option(WITH_LIBPSL "是否构建 libpsl" OFF)
set(LIBPSL_TAG "master" CACHE STRING "libpsl 版本")
set(LIBPSL_REPO "https://gitcode.com/sound/libpsl.git" CACHE STRING "libpsl 仓库地址")

# 18 定义 curl 构建 选项
option(WITH_CURL "是否构建 curl" OFF)
set(CURL_TAG "curl-8_16_0" CACHE STRING "curl 版本")
set(CURL_REPO "https://gitcode.com/sound/curl.git" CACHE STRING "curl 仓库地址")

# 18 定义 libcpr 构建 选项
option(WITH_LIBCPR "是否构建 libcpr" OFF)
set(LIBCPR_TAG "1.11.0" CACHE STRING "libcpr 版本")
set(LIBCPR_REPO "https://gitcode.com/sound/libcpr.git" CACHE STRING "libcpr 仓库地址")

# 19 定义 jsoncpp 构建 选项
option(WITH_JSONCPP "是否构建 jsoncpp" OFF)
set(JSONCPP_TAG "1.9.5" CACHE STRING "jsoncpp 版本")
set(JSONCPP_REPO "https://gitcode.com/sound/jsoncpp.git" CACHE STRING "jsoncpp 仓库地址")

# 20 定义 yaml_cpp 构建 选项
option(WITH_YAML_CPP "是否构建 yaml_cpp" OFF)
set(YAML_CPP_TAG "0.8.0" CACHE STRING "yaml_cpp 版本")
set(YAML_CPP_REPO "https://gitcode.com/sound/yaml-cpp.git" CACHE STRING "yaml_cpp 仓库地址")







# 19 定义 drogon 构建 选项
option(WITH_DROGON "是否构建 drogon" OFF)
set(DROGON_TAG "v1.9.11" CACHE STRING "drogon 版本")
set(DROGON_REPO "https://gitcode.com/sound/drogon.git" CACHE STRING "drogon 仓库地址")



# 17 定义 java se 构建 选项
option(WITH_JVN "是否构建 java se" OFF)
set(JVN_TAG "jdk-21" CACHE STRING "jvn 版本")
set(JVN_REPO "https://gitcode.com/sound/java-se-linux.git" CACHE STRING "jvn 仓库地址")

# mingw-w64 构建 选项
option(WITH_MINGW_W64 "是否构建 mingw-w64" OFF)
set(MINGW_W64_TAG "v13.0.0" CACHE STRING "mingw-w64 版本")
set(MINGW_W64_REPO "https://gitcode.com/sound/mingw-w64.git" CACHE STRING "mingw-w64 仓库地址")















